#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include <vector>
#include <functional>
int main() {
    int n, p;
    cin >> n >> p;
    vector<int> v(n, 0);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int gap = 2 * p;
    int maxn = 0;
    int left = 0;
    for (int right = 0; right < n;)
    {
        if (v[right] - v[left] <= gap)
        {
            maxn = max(maxn, right - left + 1);
            right++;
        }
        else {
            left++;
        }
    }
    cout << maxn;
    return 0;
}
#include <iostream>
using namespace std;
#include <vector>
int main() {
    int n;
    cin >> n;
    vector<int> v(n, 0);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    vector<vector<int>> dp(n, vector<int>(2, 0));
    dp[0][0] = v[0];
    for (int i = 1; i < n; i++)
    {
        dp[i][0] = max(dp[i - 1][1] + v[i], dp[i - 1][0]);
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]);
    }
    cout << max(dp[n - 1][0], dp[n - 1][1]);
    return 0;
}